<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Layout\Content;
use Encore\Admin\Grid;
use App\User;
use Encore\Admin\Controllers\ModelForm;
use App\Service\Model\Agency;
use Encore\Admin\Widgets\Form;
use App\Admin\Forms\AgencyForm;
use Encore\Admin\Show;

class AgentController extends Controller
{
    use ModelForm;
    public function index(Content $content)
    {
        return $content
            ->header('代理')
            ->description('代理人员列表')
            ->body($this->grid());
    }

    public function grid(){
        $grid = new Grid(new Agency());
        
        $grid->id('ID');
        $grid->tel('电话号码');
        $grid->name('姓名');
        $grid->level('代理级别');
        $grid->invite_code('邀请码');
        $grid->created_at('创建时间');
        $grid->disableExport();
        $grid->actions(function ($actions) {
            // $actions->disableDelete();
            // $actions->disableEdit();
      

        });
        return $grid;
    }

    

     /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('新增代理人员')
            ->body(new AgencyForm());
    }

    public function destroy($id)
    {
        Agency::destroy($id);
        admin_success('成功');

    }

    public function show($id ,Content $content){
        $show = new Show(Agency::findOrFail($id));
        $show->id('Id');
        $show->name('姓名');
        $show->tel('手机号');
        $show->parent_id('上级ID');
        return $content
        ->header('详情')
        ->description('代理用户详情')
        ->body($show);
    }

    public function edit($id , Content $content){
        return $content
        ->header('编辑')
        ->description('编辑代理')
        ->body((new AgencyForm())->edit($id));
    }
    
    

}
